﻿using System.IO;
using System.Text;
using System.Net;
using System.Xml;

using ECCIT;

namespace ECCIT.Net.SAML2.Protocols
{
    public class StatusMessage
    {
        // Fields
        private string message;

        // Properties
        public string Message
        {
            get { return this.message; }
            set { this.message = value; }
        }

        // Methods
        public StatusMessage()
        {
        }

        public StatusMessage(string message)
        {
            this.message = message;
        }

        public StatusMessage(XmlElement xmlElement)
        {
            if (!IsValid(xmlElement))
            {
                throw new SerializationException("The XML is not a StatusMessage.");
            }
            this.message = xmlElement.InnerText.Trim();
        }

        public static bool IsValid(XmlElement xmlElement)
        {
            return (xmlElement.LocalName.Equals("StatusMessage") && xmlElement.NamespaceURI.Equals("urn:oasis:names:tc:SAML:2.0:protocol"));
        }

        public override string ToString()
        {
            return this.message;
        }

        public XmlElement ToXml(XmlDocument xmlDocument)
        {
            XmlElement element = xmlDocument.CreateElement("samlp", "StatusMessage", "urn:oasis:names:tc:SAML:2.0:protocol");
            element.AppendChild(xmlDocument.CreateTextNode(this.message));
            return element;
        }
    }
}
